<?php

/**
 * intervention actions.
 *
 * @package    app_clinique
 * @subpackage intervention
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class interventionActions extends autointerventionActions
{
     public function executeCreateIntervention(){

         $this->sf_intervention = $this->getsfInterventionOrCreate();
         $this->idsejour = $this->getRequestParameter('idsejour');
         $this->sf_sejour = sfSejourPeer::retrieveByPk($this->idsejour);
         if ($this->getRequest()->getMethod() == sfRequest::POST){

                $this->updatesfInterventionFromRequest();
                $this->savesfIntervention($this->sf_intervention);
                $this->setFlash('notice', 'Vos modifications ont été enregistrées');

                return $this->redirect('intervention/show?idsejour='.$this->sf_intervention->getSejourId());

         }
         else
         {
              $this->labels = $this->getLabels();
         }
    }

    public function handleErrorCreateIntervention()
  {
    $this->preExecute();
    $this->sf_intervention = $this->getsfInterventionOrCreate();
    $this->updatesfInterventionFromRequest();

    $this->labels = $this->getLabels();
    $this->redirect('intervention/createIntervention?erreur=1&idsejour='.$this->sf_intervention->getSejourId());
  }

  public function executeShow(){
       $this->idsejour = $this->getRequestParameter('idsejour');
       $this->sf_sejour = sfSejourPeer::retrieveByPk($this->idsejour);
       //liste des interventions pour le sejour transmis en parametre
       $c = new Criteria();
       $c->add(sfInterventionPeer::SEJOUR_ID,$this->idsejour);
       $this->listeInterventions = sfInterventionPeer::doselect($c);

    }

    public function executeEdit()
  {
    $this->sf_intervention = $this->getsfInterventionOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updatesfInterventionFromRequest();

      $this->savesfIntervention($this->sf_intervention);

      $this->setFlash('notice', "L'enregistrement a été effectué");

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('intervention/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('intervention/list');
      }
      else
      {
        return $this->redirect('intervention/edit?id='.$this->sf_intervention->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }
}
